package com.xx.job.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xx.job.controller.dto.PageDTO;
import com.xx.job.entity.system.SysJob;
import com.xx.job.mapper.SysJobMapper;
import com.xx.job.service.system.SysJobService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liangcy
 * @since 2021-01-14
 */
@Service
public class SysJobServiceImpl extends ServiceImpl<SysJobMapper, SysJob> implements SysJobService {

    @Autowired
    private SysJobMapper sysJobMapper;

    @Override
    public int add(SysJob sysJob) {
        return sysJobMapper.insert(sysJob);
    }

    @Override
    public int delete(Long id) {
        return sysJobMapper.deleteById(id);
    }

    @Override
    public int update(SysJob sysJob) {
        return sysJobMapper.updateById(sysJob);
    }

    @Override
    public SysJob select(Long id) {
        return sysJobMapper.selectById(id);
    }

    @Override
    public IPage<SysJob> selectPage(PageDTO pageDTO, SysJob sysJob) {
        IPage<SysJob> page = new Page<>(pageDTO.getPageIndex(),pageDTO.getPageSize());
        QueryWrapper<SysJob> wrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(sysJob.getJobName())){
            wrapper.like("job_name",sysJob.getJobName().trim());
        }
        if(StringUtils.isNotBlank(sysJob.getJobGroup())){
            wrapper.eq("job_group",sysJob.getJobGroup());
        }
        if(sysJob.getStatus() != null){
            wrapper.eq("status",sysJob.getStatus());
        }
        return sysJobMapper.selectPage(page,wrapper);
    }
}
